package com.study.service.impl;

import com.study.service.SendMailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;

import javax.mail.internet.MimeMessage;

/**
 * @desc:
 * @author: panxiyi
 * @date: 2023/5/7 11:15 下午
 */

//@Service
public class SendMailServiceImpl implements SendMailService {

    @Autowired
    private JavaMailSender javaMailSender;

    // 发送人
    private String from = "2074992712@qq.com";
    // 接受人
    private String to = "1820111238@qq.com";
    // 标题
    private String title = "小宝贝-我来了-标题";
    // 正文
    private String context = "测试邮件正文标题";
    @Override
    public void sendMail() {
        // 发送简单邮件
//        SimpleMailMessage message = new SimpleMailMessage();
//        message.setFrom(from);
//        message.setTo(to);
//        message.setSubject(title);
//        message.setText(context);
//        javaMailSender.send(message);

        try {
            MimeMessage mimeMessage = javaMailSender.createMimeMessage();
            MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage);
            messageHelper.setFrom(from + ("peter's•pan"));
            messageHelper.setTo(to);
            messageHelper.setSubject(title);
            messageHelper.setText(context);
            javaMailSender.send(mimeMessage);
        } catch (Exception e) {

        }



    }
}
